package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import ngames.com.sushitv.R;
import ngames.com.sushitv.base.BaseListAdapter;
import ngames.com.sushitv.entity.Anime;
import ngames.com.sushitv.entity.ItemVideo;

/**
 * Created by edmond on 16-8-9.
 */
public class AnimeSingleVideoAdapter extends BaseListAdapter<ItemVideo> {
    private ArrayList<ItemVideo> videoList;
    private LayoutInflater inflater;
    //private int listSize;
    public AnimeSingleVideoAdapter(Context context, ArrayList<ItemVideo> list) {
        super(context, list);

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ItemVideoHolder(mInflater.inflate(R.layout.item_fanmade, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemVideoHolder viewHolder = (ItemVideoHolder) holder;
        viewHolder.setData(position);
    }

    @Override
    public int getItemCount() {
        if (mDataList.size()>12){
            return 12;
        }else{
            return mDataList.size();
        }

    }

    class ItemVideoHolder extends RecyclerView.ViewHolder {
        TextView titleTxt, watchedTxt, updatedTxt, playTxt, danmuTxt;
        ImageView coverImg;

        public ItemVideoHolder(View itemView) {
            super(itemView);
            titleTxt = (TextView) itemView.findViewById(R.id.titleText);
            coverImg = (ImageView) itemView.findViewById(R.id.cover);
            //watchedTxt = (TextView) itemView.findViewById(R.id.watchedText);
            updatedTxt = (TextView) itemView.findViewById(R.id.uploader);
            playTxt = (TextView) itemView.findViewById(R.id.playCountText);
            danmuTxt = (TextView) itemView.findViewById(R.id.readCountText);
        }

        public void setData(int data) {
            ItemVideo iv = mDataList.get(data);
            titleTxt.setText(iv.getTitle());
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    /*.showStubImage(R.drawable.image_is_loading)            // 设置图片下载期间显示的图片
                    .showImageForEmptyUri(R.drawable.image_loading_failed)    // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.drawable.image_loading_failed)        // 设置图片加载或解码过程中发生错误显示的图片
                   */.cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                    .cacheOnDisc(true)                            // 设置下载的图片是否缓存在SD卡中
                    .build();
            String workerImgStr = iv.getCover();
            ImageLoader.getInstance().displayImage(workerImgStr, coverImg, options);// 创建配置过得DisplayImageOption对象
            playTxt.setText(iv.getPlayCount());
            danmuTxt.setText(iv.getDanmuCount());
            //watchedTxt.setText(iv.getEpisode());
            updatedTxt.setText("Updated to EP " + iv.getEpisode());
        }
    }
}
